# Contributor: larchunix
# Maintainer: Jelle van der Waa <jelle@archlinux.org>

pkgname=libdnf
pkgver=0.70.0
pkgrel=2
pkgdesc="Library providing simplified C and Python API to libsolv"
arch=('loong64' 'x86_64')
url="https://github.com/rpm-software-management/$pkgname"
license=('GPL')
depends=('glib2' 'gpgme' 'json-c' 'libmodulemd' 'librepo' 'libsolv'
         'libutil-linux' 'openssl' 'rpm-tools' 'sqlite' 'zlib')
makedepends=('cmake' 'gtk-doc' 'python' 'python-sphinx' 'swig')
checkdepends=('check' 'cppunit')
optdepends=('python: for python bindings')
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('9934b94ad2df81d00f1bb22803130d16b9327888b7de4cd446efadd9e8c47e5f')

prepare() {
  cd "$pkgname-$pkgver"
  # TODO: libsolv installs cmake in something where libdnf can't find it
  cp -p /usr/share/cmake/Modules/FindLibSolv.cmake cmake/modules/
}

build() {
  cd "$pkgname-$pkgver"

  cmake -B build \
        -DCMAKE_BUILD_TYPE=None \
        -DCMAKE_C_FLAGS_RELEASE='-DNDEBUG' \
        -DCMAKE_CXX_FLAGS_RELEASE='-DNDEBUG' \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DPYTHON_DESIRED=3 \
        -DWITH_ZCHUNK=OFF \
        -Wno-dev

  make -C build VERBOSE=1
}

check() {
  cd "$pkgname-$pkgver"
  # tests fail
  # (/build/libdnf/src/libdnf-0.65.0/build/tests/libdnf/test_libdnf_main:5860): libdnf-WARNING **: 12:55:05.175: Can't read plugin directory "/usr/lib/libdnf/plugins/": No such file or directory
  # error: cannot open Packages database in /var/lib/rpm
  # make -C build test ARGS="--output-on-failure"
}

package() {
  cd "$pkgname-$pkgver"

  make -C build DESTDIR="$pkgdir/" install

  install -Dp -m644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}
